<?php

namespace App\Admin\Controllers;

use Encore\Admin\Form;
use App\Models\ConfigSale;
use Encore\Admin\Controllers\AdminController;

class ConfigSalesController extends AdminController
{
	protected $title = '仟商集配置';
	
    protected function form()
    {
        $form = new Form(new ConfigSale());
		
		/*$form->currency('apple_actual_price', '苹果实际价格')->symbol('￥')->default(5.00)->rules('required');
	    $form->currency('vip_price', '会员账号售价')->symbol('￥')->default(19.90)->rules('required');
	    $form->number('vip_period', '会员账号有效期/日')->default(30)->min(1)->max(31);*/
	    $form->number('give_team_levels', '发放佣金层级')->min(0)->default(6)->rules('required');
	    $form->number('auto_upgrade_needs_children', '升团长所需下单会员数')->min(0)->default(6)->rules('required');
	    $form->number('auto_upteam_needs_children', '升高级团长所需团长')->min(0)->default(10)->rules('required');

	    $form->divider();

	    $form->rate('order_own_rewards_percent', '自购返佣比例')->default(33);
	    $form->rate('order_parent_rewards_percent', '上级订单返佣比例')->default(33);
	    $form->rate('order_team_rewards_percent', '团队订单返佣比例')->default(33);

	    $form->rate('order_commander_rewards_percent', '带货团长返佣比例')->default(50);
	    $form->rate('order_senior_commander_rewards_percent', '高级团长返佣比例')->default(100);
	    $form->rate('one_person_group_rewards', '邀请一人成团奖励比例')->default(20);
	    $form->rate('two_person_group_rewards', '邀请两人成团奖励比例')->default(40);
	    $form->rate('more_person_group_rewards', '邀请三人成团奖励比例')->default(100);

	    $form->timeRange('start_at', 'end_at', '抢购时间范围');

	    $form->number('card_expired', '开团卡过期时间')->min(0)->default(10)->rules('required');
	    $form->number('group_expired', '开团过期时间')->min(0)->default(3)->rules('required');

	    //$form->radio('group_expired', '开团过期时间')->min(0)->default(3)->rules('required');
	   
	     $form->radio('is_group_open', '开团列表开关')
		    ->options(config('site.bool'))
		    ->default(false);
	    
	    $this->formTools($form);
	    $this->formFooter($form);
	    $this->formSaved($form);
	    
        return $form;
    }
	
	protected function formTools(Form $form)
	{
		$form->tools(function (Form\Tools $tools) {
			$tools->disableList();
			$tools->disableView();
			$tools->disableDelete();
		});
	}
	
	protected function formFooter(Form $form)
	{
		$form->footer(function (Form\Footer $footer) {
			$footer->disableReset();
			$footer->disableViewCheck();
			$footer->disableCreatingCheck();
			$footer->disableEditingCheck();
		});
	}
	
	protected function formSaved(Form $form)
	{
		$form->saved(function () {
			admin_toastr('仟商集配置', 'success');
			return redirect(route('admin.config-sales.edit', 1));
		});
	}
}
